﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Utils;
using DataHelper;

namespace DAL
{
    public class ShortageDao
    {
        public bool Insert(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }


        public bool Update(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }

        public bool DeleteOneInfo(string shortageID)
        {
            return SQLHelper.ExecuteSqlWithTransaction("Delete from Wage_Shortage Where ShortageID=" + shortageID);
        }
        //获取一条记录
        public DataTable GetOneInfo(string shortageID)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from Wage_Shortage Where ShortageID=" + shortageID);
        }
        public DataTable GetLists(string deptName, string serWord, string bTime, string eTime)
        {
            StringBuilder str = new StringBuilder("select * from Wage_Shortage Where 1=1 ");
            if (!string.IsNullOrWhiteSpace(serWord))
                str.Append(" And (EmpCode='" + serWord + "' Or EmpName Like '%" + serWord + "%') ");
            else
            {
                if (deptName != "")
                    str.Append(" and DeptName='" + deptName + "' ");
                if (RegexRule.IsDate(bTime))
                    str.Append(" And RewardsTime>='" + bTime + "'");
                if (RegexRule.IsDate(eTime))
                    str.Append(" And RewardsTime<='" + eTime + "'");
            }
            str.Append(" Order by InputTime DESC");
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(str.ToString());
            return dt;
        }
        public DataTable GetOutLists(string deptName, string serWord, string bTime, string eTime)
        {
            string fields = XmlUtility.ReadFiled("Wage_Shortage");
            StringBuilder str = new StringBuilder("select " + fields + " from Wage_Shortage Where 1=1 ");
            if (!string.IsNullOrWhiteSpace(serWord))
                str.Append(" And (EmpCode='" + serWord + "' Or EmpName Like '%" + serWord + "%') ");
            else
            {
                if (deptName != "")
                    str.Append(" and DeptName='" + deptName + "' ");
                if (RegexRule.IsDate(bTime))
                    str.Append(" And RewardsTime>='" + bTime + "'");
                if (RegexRule.IsDate(eTime))
                    str.Append(" And RewardsTime<='" + eTime + "'");
            }
            str.Append(" Order by InputTime DESC");
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(str.ToString());
            return dt;
        }

       

    }
}
